//
//  GAOMainController.swift
//  Weibo28
//
//  Created by 高辰 on 16/5/10.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import SVProgressHUD
class GAOMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //使用自定义tabBar
        let customTabBar = GAOTabBar()
        //用KVC给只读属性设置值
        setValue(customTabBar, forKey: "tabBar")
        
        customTabBar.composeButtonClosure = {[weak self] in
            //  判断用户是否登陆
            if GAOUserAccountViewModel.UserAccountViewModel.isLogin {
                self?.showComposeVC()
            } else {
                SVProgressHUD.showErrorWithStatus("您未登陆,请先登录!")
            }

            
//            self?.showComposeVC()
        }
        
        
        //添加子控制器
        addChildViewController(GAOHomeController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(GAOMessageController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(GAODiscoverController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(GAOProfileController(), title: "我的", imageName: "tabbar_profile")
        
    }

    
    func addChildViewController(childController: UIViewController, title: String, imageName: String) {
        
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        //设置选中图片,同时修改图片渲染模式
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置tabBarItem选中状态文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        //设置tabBarItem文字大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(15)], forState: UIControlState.Normal)
        //添加子视图控制器
        let nav = UINavigationController(rootViewController: childController)
        addChildViewController(nav)
    }
    
    
    // 进入发微博界面
    private func showComposeVC() {
        
        let composeVC = GAOComposeController()
        let nav = UINavigationController(rootViewController: composeVC)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
    
    
    
    
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
